home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11793 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: news.voicenet.com!usenet
  2. From: deaton@cygnus.rsabbs.com
  3. Newsgroups: comp.lang.c++
  4. Subject: Structure names are pointers? Writing to them?
  5. Date: 16 Mar 1996 06:17:28 GMT
  6. Organization: Voicenet - Internet Access - (215)674-9290
  7. Message-ID: <4idmdo$2b2@news.voicenet.com>
  8. NNTP-Posting-Host: d02.rsabbs.com
  9. X-Newsreader: SPRY News 3.03 (SPRY, Inc.)
  10.  
  11.  
  12.    I'm using several random access data files in my program(Written in TurboC/C++), and all except for one are ARRAYS of STRUCTURES.
  13. With these files, I have no syntax problems reading and writing to them. 
  14. For instance:
  15.  
  16. FILE * fptr;                         
  17. blahS blah[15];
  18.  
  19. ...code to populate structure...
  20.  
  21. fptr=fopen("blah.dat","w+");
  22. fwrite(blah,sizeof(blah),1,fptr);
  23. fclose(fptr);
  24.  
  25. This bit of code works fine, but when I try to write only one structure:
  26.  
  27. FILE * fptr;                         
  28. blahS blah;
  29.  
  30. ...code to populate structure...
  31.  
  32. fptr=fopen("blah.dat","w+");
  33. fwrite(blah,sizeof(blah),1,fptr);
  34. fclose(fptr);
  35.  
  36. my compiler spits out an error. As far as I understood, structure names acted the
  37. same way as array names: they are pointers. So why isn't this working? I really don't
  38. want to declare a structure array of 1 element. It would work, but that would be pretty lame.
  39.  
  40. Thankyou :),
  41.  
  42. The Hermit
  43. deaton@cygnus.rsabbs.com 
  44.